﻿using AbpApplication.InPut;
using CommunityToolkit.Mvvm.Input;
using HandyControl.Controls;
using NewWms.Apiservice;
using NewWms.Apiservice.Dto;
using NewWms.Extend;
using Prism.Mvvm;
using Prism.Regions;
using Reconstruct_Desktop.Apiservice.Dto;
using Reconstruct_Desktop.Apiservice.InPut;
using System;
using System.Collections;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using WcsZz.Extend;

namespace Reconstruct_Desktop.ViewModels.ManualOperateViewModel
{
    public partial class EmptyBoxViewModel : BindableBase, INavigationAware
    {

        private readonly IBaseService_Client baseService_Client;
        private readonly IViewService_Client viewService_Client;
        private long count;
        public long Count
        {
            get { return count; }
            set { count = value; RaisePropertyChanged(); }
        }
        private long pagecount;
        public long PageCount
        {
            get { return pagecount; }
            set { pagecount = value; RaisePropertyChanged(); }
        }
        private InPut_ViewService14_Client inPut_ViewService14_Client;
        public  InPut_ViewService14_Client InPut_ViewService14_Client
        {
            get { return inPut_ViewService14_Client; }
            set { inPut_ViewService14_Client = value; RaisePropertyChanged();}
        }

        private List<EmptyMaterialRatioDto> emptyMaterialRatioDtos;
        public List<EmptyMaterialRatioDto> EmptyMaterialRatioDtos
        {
            get { return emptyMaterialRatioDtos; }
            set { emptyMaterialRatioDtos = value;RaisePropertyChanged(); }
        }


        public EmptyBoxViewModel() 
        {

            baseService_Client=new BaseService_Client();
            viewService_Client=new ViewService_Client();
            InPut_ViewService14_Client=new InPut_ViewService14_Client();
            InPut_ViewService14_Client.PageIndex = 1;
            InPut_ViewService14_Client.PageSize = 50;
            InPut_ViewService14_Client.BoxGridQuantity = "1";
        }

        //获取视图
        [RelayCommand]
        private async void GetView()
        {
       
            var tuple=  await  viewService_Client.View_BoxProportion(InPut_ViewService14_Client);
            EmptyMaterialRatioDtos = tuple.Item1;
            Count = (long)tuple.Item2;
            PageCount = (long)tuple.Item3;
        }
        //下架 agv任务
        [RelayCommand]
        private async void CreateTaskOrderOut(IList SelectItems)
        {
            InPut_BaseService13_Client inPut = new InPut_BaseService13_Client();
            inPut.InlethouseCode = GlobalVariable.InletCode;
            if (string.IsNullOrEmpty(inPut.InlethouseCode))
            {
                MessageBox.Info("请输入出库口");
                return;
            }
            foreach (EmptyMaterialRatioDto item in SelectItems)
            {
                inPut.BoxCodes.Add(item.BoxCode);
            }
            inPut.Machine = int.Parse(GlobalVariable.Machine);
            Tuple<bool, List<TaskOrderDto>> tuple = await baseService_Client.CreateTaskOrderOut(inPut);
            if (tuple.Item1)
            {
                EventAggregatorHelper.EventAggregator.SendMessage("修改成功", "跳转页面");
                GetView();
            }

        }


        //主页设置
        private string title = "空箱跟踪";
        public string Title
        {
            get { return title; }
            set { title = value; RaisePropertyChanged(); }
        }
        public bool IsNavigationTarget(NavigationContext navigationContext)
        {
            return true;
        }
        public async void OnNavigatedFrom(NavigationContext navigationContext)
        {

        }
        public async void OnNavigatedTo(NavigationContext navigationContext)
        {
     
            GetView();
        }

    }
}
